package com.example.protocol.paxos;

import lombok.Getter;

@Getter
public class Acceptor {
    private int promisedId = -1;
    private int acceptedId = -1;
    private String acceptedValue = null;

    public synchronized boolean prepare(int proposalId) {
        if (proposalId > promisedId) {
            promisedId = proposalId;
            return true;
        }
        return false;
    }

    public synchronized boolean accept(int proposalId, String value) {
        if (proposalId >= promisedId) {
            acceptedId = proposalId;
            acceptedValue = value;
            return true;
        }
        return false;
    }

}
